package com.ganeshkrishnan.globald.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ganeshkrishnan.globald.abstracts.GenericDaoHibernate;
import com.ganeshkrishnan.globald.dao.DeploymentDao;
import com.ganeshkrishnan.globald.model.Deployment;

@Repository
@Transactional
public class DeploymentDaoHibernate extends GenericDaoHibernate<Deployment, Long> implements DeploymentDao {
	public DeploymentDaoHibernate() {
		super(Deployment.class);
	}

	@SuppressWarnings("unchecked")
	public List<Deployment> findDeploymentsByPersonID(Long PersonID) {
		return getHibernateTemplate().find("from Deployment where PersonID=?", PersonID);
	}

	@SuppressWarnings("unchecked")
	public List<Deployment> findDeploymentsByPersonIDAndType(Long PersonID, int depType) {
		return getHibernateTemplate().find(
				"from Deployment where PersonID=" + PersonID + " AND resourceType=" + depType);
	}

	public Deployment findDeploymentByID(Long PersonID, Long depID) {
		List l = getHibernateTemplate().find("from Deployment where PersonID=" + PersonID + " AND ID=" + depID);
		return (Deployment) l.get(0);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Deployment> findDeploymentsByLocation(long locID) {
		return getHibernateTemplate().find("from Deployment where locationID=" + locID);
	}
}
